package com.aliyun.heiyu.powermaster.server.rotary.utils;

import com.google.common.collect.Queues;
import java.util.concurrent.*;

/**
 * @Description 线程池
 * @Date 2019/12/11 15:51
 **/
@Deprecated
public class ThreadPoolUtil {
    /**
     * 线程数是内核数的1.5-2倍最佳
     */
    private static final int THREADS = 16;

    /**
     * 线程等待队列长度
     * 防止无限长导致oom问题
     */
    private static final int QUEUE_SIZE = 50;

    private static final BlockingQueue LINKED_BLOCKING_QUEUE = Queues.newLinkedBlockingQueue(QUEUE_SIZE);

    private final static ThreadPoolExecutor THREADPOOL_EXECUTOR = new ThreadPoolExecutor(THREADS, THREADS, 0, TimeUnit.MILLISECONDS,
        LINKED_BLOCKING_QUEUE, new ThreadPoolExecutor.CallerRunsPolicy()
    );

    public static Future submitFuture(Callable c) {
        return THREADPOOL_EXECUTOR.submit(c);
    }

    public static void submit(Runnable r) {
        THREADPOOL_EXECUTOR.submit(r);
    }

    public static void execute(Runnable r) {
        THREADPOOL_EXECUTOR.execute(r);
    }

}
